<template>
  <div class="drawingCraftsman">
    <van-steps :active="active" active-color="#38f">
      <van-step>申请</van-step>
      <van-step>图集选用</van-step>
      <van-step>签订合同</van-step>
      <van-step>四到场</van-step>
    </van-steps>
    <div style="background-color: #f6f6f6; height: 14px; margin-top: 4px"></div>
    <div v-if="files.length>0" id="hamburger-container" style="background: #ffffff;padding-left: 20px; z-index:100000!important padding: 0px 34px; font-size: 17px; color: #000; border-bottom: 1px solid #d2d2d2">
      <div style="line-height: 22px">附件</div>
      <van-cell-group>
        <van-cell v-show="files[0].TJS" title="条件书:" value="条件书.pdf" @click="handkleGoPdf('1')" />
        <van-cell v-show="files[0].YCXGZS" title="一次性告知书:" value="一次性告知书.pdf" @click="handkleGoPdf('2')" />
        <van-cell v-show="files[0].BZGZS" title="补正告知书:" value="补正告知书.pdf" @click="handkleGoPdf('3')" />
      </van-cell-group>
    </div>
    <inputSelect :isShowCity="false" :contentData.sync="tjxxData" :JFData.sync="JFData" :title="''" @getValues="getValues" />
    <div style="display: flex; justify-content: space-between; align-items: center; margin-top: 20%;padding: 0 10px;">
      <van-button type="primary" @click="JFTZClick('建房图纸')" style="width: 45vw">选择图纸</van-button>
      <van-button type="primary" @click="handleToClick" style="width: 45vw">提交</van-button>
    </div>
  </div>
</template>

<script>
import inputSelect from '../NewZzd/public/inputSelect'
import { GSA_Add, GSA_Search } from '@/common/commonApi'
import { useSend } from './send' 
export default {
  name: 'drawingCraftsman',
  data() {
    return {
      // 页面数据
      active: 1,
      tableData: {},
      rowData: {},
      JFData: [
        {
          TJLX: '158',
          TJBH: '',
          TJMC: '',
          JZCS: '',
          JZFG: '',
          DJJC: '',
          SJDWMC: '',
          SJDWFZR: '',
          ROW_GUID: '',
          TJPKID: '',
          TO_ROW_GUID: ''
        }
      ],
      tjxxData: [
        {
          label: '图集类型',
          key: 'TJLX', //绑定的字段
          ISinput: false, //true:输入框
          required: true, //true: 必填项
          readonly: false, //true:可以填写 false：不可以填写
          isTime: false, //true:可以时间选择器 false：下拉框
          // buttonTest: "",
          emitData: '9b93f111-a6a3-4eac-a86f-f4b7e1ff4b30',
          NYDARR: []
        },
        {
          label: '图集名称',
          key: 'TJMC', //绑定的字段
          ISinput: true, //true:输入框
          required: true, //true: 必填项
          readonly: false, //true:可以填写 false：不可以填写
          isTime: false //true:可以时间选择器 false：下拉框
        },
        {
          label: '图集编号',
          key: 'TJBH', //绑定的字段
          ISinput: true, //true:输入框
          required: true, //true: 必填项
          readonly: false, //true:可以填写 false：不可以填写
          isTime: false //true:可以时间选择器 false：下拉框
        },
        {
          label: '建筑层数',
          key: 'JZCS', //绑定的字段
          ISinput: true, //true:输入框
          required: true, //true: 必填项
          readonly: false, //true:可以填写 false：不可以填写
          isTime: false //true:可以时间选择器 false：下拉框
        }
      ],
      files:[]
    }
  },
  mounted() {
    // 页面初始化方法
    //选择完之后回显数据
    this.rowData = this.$store.state.TJROWDATA
    let TJXQ = this.$store.state.TJDATAV2
    this.getFile()
    if (TJXQ != {}) {
      this.JFData[0].TJMC = TJXQ.atlasName
      if (TJXQ.atlasStyle == '通用图集') {
        this.JFData[0].TJLX = '157'
        this.JFData[0].JZCS = TJXQ.floors
        this.JFData[0].TJBH = TJXQ.id
        this.JFData[0].JZFG = TJXQ.atlasType
        this.JFData[0].SJDWMC = TJXQ.technicalUnit?.qymc
        this.JFData[0].SJDWFZR = TJXQ.technicalUnit?.lxr
      } else {
        this.JFData[0] = TJXQ
      }
    }
    // 页面初始化方法
    this.init()
  },
  components: {
    inputSelect
  },
  methods: {
    init() {
      // 初始化方法
      // ba906ba1-8d90-42da-971c-3ad7995f92c0   保存视图
    },
    getValues(name, value, label) {
      console.log(name, value, label, this.JFData)
    },
    async getFile(){
      let data = [{ field: 'TO_ROW_GUID', value: this.rowData.ROW_GUID }]
      const res = await GSA_Search('95564bb6-4d54-4574-9674-72b886090e95', data)
      this.files = res.Data
    },
    handkleGoPdf(item) {
      var groupGuid = ''
      var dataGuid = '951fb981-aedf-4144-b9ea-1aee47a188ae'
      if (item == '1') {
        groupGuid = '{AB92CB36-C34F-45B5-A272-E0887E959207}'
      } else if (item == '2') {
        groupGuid = '{AE2F0B7A-7AF9-489B-B9F1-ECAEB6E9D343}'
      } else {
        groupGuid = '{26EB6459-0043-4093-AFDC-364B0781FF7C}'
      }
      let baseurl = this.rowData.F_WAIWANGIP .replace(/#/g, ':')
      let url = baseurl + '/PrintServer/api/PreviewWordRpt?groupGuid=' + groupGuid + '&toRowGuid=' + this.rowData.ROW_GUID + '&dataGuid=' + dataGui

      let url1 = window.g.BaseURL + '/api/farmerHouse/proxy/dataTransFile/v2?fileUrl=' + encodeURIComponent(url)
      ZWJSBridge.openLink({
        url: url1
      })
        .then((res) => {})
        .catch((err) => {
          window.open(url1)
        })
    },
    //保存数据
    async handleToClick() {
      //需要传入ROW_GUID和TO_ROW_GUID
      //没选不让提交
      if(!this.JFData[0].TJBH){
        this.$toast.fail('请先选择图集')
        return
      }
      this.JFData[0].ROW_GUID = this.rowData.ROW_GUID
      this.JFData[0].TO_ROW_GUID = this.rowData.TO_ROW_GUID
      const date = await GSA_Add('ba906ba1-8d90-42da-971c-3ad7995f92c0', true, this.JFData[0])
      //发送
      useSend(this.rowData,this.callBack)
    },
    callBack(){
      //发送成功之后的回调
      this.$toast.success('发送成功')
      this.$router.push({
        path:'./zljindex'
      })
    },
    JFTZClick(data) {
      debugger
      console.log(this.tableData)
      switch (data) {
        case '建房图纸':
          window.localStorage.setItem('routerData', '')
          debugger
          this.$router.push({
            path: '/BuildingServerv2',
            query: {
              id: 'ChooseCraftsman',
              data: JSON.stringify(this.rowData),
              data10: '1'
            }
          })
          break
      }
    }
  },
  created() {
    console.log(this.$route.query.data)
    try {
      if (JSON.parse(this.$route.query?.data).ROW_GUID) {
        this.$store.commit('getTJROWDATA', JSON.parse(this.$route.query.data))
      }
    } catch (error) {
      console.log(error)
    }
  }
}
</script>

<style lang="scss" scoped></style>

<style>
.van-cell__title {
  color: black;
  font-weight: 780;
}

.van-cell__value {
  color: #38f;
}
</style>

<style>
.drawingCraftsman .van-radio-group--horizontal {
  padding-left: 8px !important;
}

.drawingCraftsman .van-field__control {
  text-align: right;
}
</style>
